package view;


import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import model.DIRECTION;

public class KeyboardListener extends KeyAdapter{
	
	private Mario parent;
	
	public KeyboardListener(Mario parent){
		this.parent = parent;
		
	}
	
	public void keyPressed(KeyEvent e) {

        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
        	
        	parent.moveEventHandler(DIRECTION.LEFT, true);
        }

        if (key == KeyEvent.VK_RIGHT) {
        	parent.moveEventHandler(DIRECTION.RIGHT, true);
        }

        if (key == KeyEvent.VK_UP) {
        	parent.moveEventHandler(DIRECTION.UP, true);
        }

        if (key == KeyEvent.VK_DOWN) {
        	parent.moveEventHandler(DIRECTION.DOWN, true);
        }
    }

    public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
        	parent.moveEventHandler(DIRECTION.LEFT, false);
        }

        if (key == KeyEvent.VK_RIGHT) {
        	parent.moveEventHandler(DIRECTION.RIGHT, false);
        }

        if (key == KeyEvent.VK_UP) {
        	parent.moveEventHandler(DIRECTION.UP, false);
        }

        if (key == KeyEvent.VK_DOWN) {
        	parent.moveEventHandler(DIRECTION.DOWN, false);
        }
    }

}
